MODULE_NAME='IR AVR'
(
	Dev dvRcvr,
	Dev vdvRcvr
)
(***********************************************************)
(***********************************************************)
(*  FILE_LAST_MODIFIED_ON: 04/04/2006  AT: 11:33:16        *)
(***********************************************************)
(* System Type : NetLinx                                   *)
(***********************************************************)
(* REV HISTORY:                                            *)
(***********************************************************)
(*
    $History: $
*)    
(***********************************************************)
(*          DEVICE NUMBER DEFINITIONS GO BELOW             *)
(***********************************************************)
DEFINE_DEVICE

(***********************************************************)
(*               CONSTANT DEFINITIONS GO BELOW             *)
(***********************************************************)
DEFINE_CONSTANT
cnChanPowerOn     = 1
cnChanPowerOff    = 2
cnChanVolumeUp    = 3
cnChanVolumeDown  = 4
cnChanMuteToggle  = 5
cnChanMuteOn      = 6
cnChanMuteOff     = 7
cnChanInputTV     = 8
cnChanInputDVD    = 9
cnChanInputVCR1   = 10
cnChanInputDSS    = 11
cnChanInputAux1   = 12
cnChanInputAux2   = 13
cnChanInputCD     = 14
cnChanInputTape   = 15
cnChanInputTuner  = 16
cnChanInputFM     = 17
cnChanInputAM     = 18
cnChanInputXM     = 19
cnChan7_1ChannelOn    = 20
cnChan7_1ChannelOff   = 21
cnChanTunerPreset1    = 22
cnChanTunerPreset2    = 23
cnChanTunerPreset3    = 24
cnChanTunerPreset4    = 25
cnChanTunerPreset5    = 26
cnChanTunerPreset6    = 27
cnChanTunerPreset7    = 28
cnChanTunerPreset8    = 29
cnChanTunerPreset9    = 30
cnChanTunerPreset10   = 31
cnChanTunerPresetUp   = 32
cnChanTunerPresetDown = 33
cnChanTunerFreqUp     = 34
cnChanTunerFreqDown   = 35


cnCmdPowerOn         = 27
cnCmdPowerOff        = 28
cnCmdVolumeUp        = 24
cnCmdVolumeDown      = 25
cnCmdMute            = 26
cnCmdInputSelectTV   = 87
cnCmdInputSelectDVD  = 88
cnCmdInputSelectVCR1 = 81
cnCmdInputSelectDSS  = 999
cnCmdInputSelectAUX1 = 86
cnCmdInputSelectAUX2 = 999
cnCmdInputSelectCD   = 60
cnCmdInputSelectTape = 62
cnCmdInputSelectTuner= 60
cnCmdInputSelectFM   = 999
cnCmdInputSelectAM   = 999
cnCmdInputSelectXM   = 999
cnCmdTunerPreset1    = 999
cnCmdTunerPreset2    = 999
cnCmdTunerPreset3    = 999
cnCmdTunerPreset4    = 999
cnCmdTunerPreset5    = 999
cnCmdTunerPreset6    = 999
cnCmdTunerPreset7    = 999
cnCmdTunerPreset8    = 999
cnCmdTunerPreset9    = 999
cnCmdTunerPreset0    = 999
cnCmdTunerPresetUp   = 999
cnCmdTunerPresetDown = 999
cnCmdTunerFreqUp     = 999
cnCmdTunerFreqDown   = 999


(***********************************************************)
(*              DATA TYPE DEFINITIONS GO BELOW             *)
(***********************************************************)
DEFINE_TYPE

(***********************************************************)
(*               VARIABLE DEFINITIONS GO BELOW             *)
(***********************************************************)
DEFINE_VARIABLE

Volatile Integer nChannels[] =
{
cnChanPowerOn,
cnChanPowerOff,
cnChanVolumeUp,
cnChanVolumeDown,
cnChanMuteToggle,
cnChanMuteOn,
cnChanMuteOff,
cnChanInputTV,
cnChanInputDVD,
cnChanInputVCR1,
cnChanInputDSS,
cnChanInputAux1,
cnChanInputAux2,
cnChanInputCD,
cnChanInputTape,
cnChanInputTuner,
cnChanInputFM,
cnChanInputAM,
cnChanInputXM
}

(***********************************************************)
(*               LATCHING DEFINITIONS GO BELOW             *)
(***********************************************************)
DEFINE_LATCHING

(***********************************************************)
(*       MUTUALLY EXCLUSIVE DEFINITIONS GO BELOW           *)
(***********************************************************)
DEFINE_MUTUALLY_EXCLUSIVE

(***********************************************************)
(*        SUBROUTINE/FUNCTION DEFINITIONS GO BELOW         *)
(***********************************************************)
(* EXAMPLE: DEFINE_FUNCTION <RETURN_TYPE> <NAME> (<PARAMETERS>) *)
(* EXAMPLE: DEFINE_CALL '<NAME>' (<PARAMETERS>) *)

Define_Call 'PULSE_IR' (Integer nCHAN)
{
  Send_Command dvRcvr,"'SP',nChan"
}

Define_Call 'SELECT_INPUT' (Integer nCHAN)
{
    Cancel_Wait 'INPUT_WAIT'
    If (![vdvRcvr,cnChanPowerOn])
    {
	Send_Command dvRcvr,"'SP',nChan"
	Wait 100 'INPUT_WAIT'
	{
	    Send_Command dvRcvr,"'SP',nChan"
	    On[vdvRcvr,cnChanPowerOn]
	    Off[vdvRcvr,cnChanPowerOff]
	}
    }
    Else
    {
	Send_Command dvRcvr,"'SP',nChan"
    }
}

(***********************************************************)
(*                STARTUP CODE GOES BELOW                  *)
(***********************************************************)
DEFINE_START
    

(***********************************************************)
(*                THE EVENTS GO BELOW                      *)
(***********************************************************)
DEFINE_EVENT

Button_Event[vdvRcvr,nChannels]
{
    Push:
    {
	Send_Level vdvRcvr,1,999 // tell the global this zone doesnt have volume control
	Switch (Button.Input.Channel)
	{
	    Case cnChanPowerOn:
	    {
		Call 'PULSE_IR' (cnCmdPowerOn)
		Wait 250 'INPUT_WAIT'
		{
		    On[vdvRcvr,cnChanPowerOn]
		    Off[vdvRcvr,cnChanPowerOff]
		}
	    }
	    Case cnChanPowerOff:
	    {
		Call 'PULSE_IR' (cnCmdPowerOff)
		Off[vdvRcvr,cnChanPowerOn]
		On[vdvRcvr,cnChanPowerOff]
	    }
	    Case cnChanVolumeUp:
	    {
		On[dvRcvr,cnCmdVolumeUp]
	    }
	    Case cnChanVolumeDown:
	    {
		On[dvRcvr,cnCmdVolumeDown]
	    }
	    Case cnChanMuteToggle:
	    {
		Call 'PULSE_IR' (cnCmdMute)
	    }
	    Case cnChanInputTV:
	    {
		Call 'SELECT_INPUT' (cnCmdInputSelectTV)
	    }
	    Case cnChanInputDVD:
	    {
		Call 'SELECT_INPUT' (cnCmdInputSelectDVD)
	    }
	    Case cnChanInputVCR1:
	    {
		Call 'SELECT_INPUT' (cnCmdInputSelectVCR1)
	    }
	    Case cnChanInputDSS:
	    {
		Call 'SELECT_INPUT' (cnCmdInputSelectDSS)
	    }
	    Case cnChanInputAux1:
	    {
		Call 'SELECT_INPUT' (cnCmdInputSelectAUX1)
	    }
	    Case cnChanInputAux2:
	    {
		Call 'SELECT_INPUT' (cnCmdInputSelectAUX2)
	    }
	    Case cnChanInputCD:
	    {
		Call 'SELECT_INPUT' (cnCmdInputSelectCD)
	    }
	    Case cnChanInputTape:
	    {
		Call 'SELECT_INPUT' (cnCmdInputSelectTape)
	    }
	    Case cnChanInputTuner:
	    {
		Call 'SELECT_INPUT' (cnCmdInputSelectTuner)
	    }
	    Case cnChanInputFM:
	    {
		Call 'SELECT_INPUT' (cnCmdInputSelectFM)
	    }
	    Case cnChanInputAM:
	    {
		Call 'SELECT_INPUT' (cnCmdInputSelectAM)
	    }
	    Case cnChanInputXM:
	    {
		Call 'SELECT_INPUT' (cnCmdInputSelectXM)
	    }
	    Case cnChanTunerPreset1:
	    {
		Call 'PULSE_IR' (cnCmdTunerPreset1)
	    }
	    Case cnChanTunerPreset2:
	    {
		Call 'PULSE_IR' (cnCmdTunerPreset2)
	    }
	    Case cnChanTunerPreset3:
	    {
		Call 'PULSE_IR' (cnCmdTunerPreset3)
	    }
	    Case cnChanTunerPreset4:
	    {
		Call 'PULSE_IR' (cnCmdTunerPreset4)
	    }
	    Case cnChanTunerPreset5:
	    {
		Call 'PULSE_IR' (cnCmdTunerPreset5)
	    }
	    Case cnChanTunerPreset6:
	    {
		Call 'PULSE_IR' (cnCmdTunerPreset6)
	    }
	    Case cnChanTunerPreset7:
	    {
		Call 'PULSE_IR' (cnCmdTunerPreset7)
	    }
	    Case cnChanTunerPreset8:
	    {
		Call 'PULSE_IR' (cnCmdTunerPreset8)
	    }
	    Case cnChanTunerPreset9:
	    {
		Call 'PULSE_IR' (cnCmdTunerPreset9)
	    }
	    Case cnChanTunerPreset10:
	    {
		Call 'PULSE_IR' (cnCmdTunerPreset0)
	    }
	    Case cnChanTunerPresetUp:
	    {
		Call 'PULSE_IR' (cnCmdTunerPresetUp)
	    }
	    Case cnChanTunerPresetDown:
	    {
		Call 'PULSE_IR' (cnCmdTunerPresetDown)
	    }
	    Case cnChanTunerFreqUp:
	    {
		Call 'PULSE_IR' (cnCmdTunerFreqUp)
	    }
	    Case cnChanTunerFreqDown:
	    {
		Call 'PULSE_IR' (cnCmdTunerFreqDown)
	    }
	}
    }
    Release:
    {
	Switch (Button.Input.Channel)
	{
	    Case cnChanVolumeUp:
	    {
		Off[dvRcvr,cnCmdVolumeUp]
	    }
	    Case cnChanVolumeDown:
	    {
		Off[dvRcvr,cnCmdVolumeDown]
	    }
	}
    }
}

(***********************************************************)
(*            THE ACTUAL PROGRAM GOES BELOW                *)
(***********************************************************)
DEFINE_PROGRAM

(***********************************************************)
(*                     END OF PROGRAM                      *)
(*        DO NOT PUT ANY CODE BELOW THIS COMMENT           *)
(***********************************************************)
